﻿
using System.Collections.Generic;
using System.Transactions;
using iss.sg4210.se18.team6s.jass.DAL;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL;

namespace iss.sg4210.se18.team6s.jass.BL
{
    public class AdvertisementFacade
    {
        IAdvertisement advertisementRepo = null;
        IAdvertisementSkill advertisementSkillRepo = null;
        public AdvertisementFacade()
        {
            advertisementRepo = new AdvertisementDAO();
            advertisementSkillRepo = new AdvertisementSkillDAO();
        }

        public void AddAdvertisement(Advertisement advertisement, List<AdvertisementSkill> advertisementSkills)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                advertisementRepo.AddAdvertisement(advertisement);

                foreach (AdvertisementSkill advertisementSkill in advertisementSkills)
                    advertisementSkillRepo.AddAdvertisementSkill(advertisementSkill);

                ts.Complete();
            }
        }
    }
}
